/**
 * 
 */
package com.etlmaster.executor.steps.control;

import com.etlmaster.executor.StepMeta;
import com.etlmaster.executor.annotation.StepInstruction;
import com.etlmaster.executor.steps.control.ControlStep;
import com.etlmaster.executor.utils.DpExecutorUtils;
import com.etlmaster.executor.utils.StepState;

/**
 * 赋值操作
 * @author MeiKefu
 * @date 2014-9-4 
 */
@StepInstruction("var")
public class AssignStep extends ControlStep{
	
	private AssignStepMeta meta;
	
	
	public AssignStep(StepMeta meta) {
		super(meta);
		this.meta=(AssignStepMeta)meta;
	}

	@Override
	protected int handle() {
		try{
			//替换回车换行符号
			String expression = this.meta.getExpression();
			expression=DpExecutorUtils.replaceMultiSpaceToOneSpace(expression).trim();
			AssignProcessor processor=null;
			if(meta.getParatype().startsWith("sql")){
				processor=new AssignSqlProcessor();
			}else if(meta.getParatype().startsWith("file")){
				processor=new AssignFileProcessor();
			}else if (meta.getParatype().startsWith("timestamp")){
				processor=new AssignTimeStampProcessor();
			}else{
				processor=new AssignObjectProcessor();
			}
			return processor.assign(expression, meta);
		}catch(Exception e){
			meta.log("ERROR","赋值失败{}",e.getMessage());
			return StepState.RUNNING_FAILED;
		}
	}

	@Override
	public boolean stop() {
		return false;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
	}
}
